//
// Created by dxyinme on 2021/10/2.
//

#include "util.h"

namespace Vsort {

VListNode<int>* NewRandomIntVList(int len) {
  std::vector<int> o;
  o.reserve(len);
  for (int i = 0; i < len; i ++) {
    o.push_back(i);
  }
  std::shuffle(o.begin(), o.end(), std::mt19937(std::random_device()()));
  return CopyFromVectorInt(o);
}

VListNode<int>* CopyFromVectorInt(std::vector<int>& vec) {
  auto* tmpAns = new VListNode<int>();
  auto* ans = tmpAns;
  for (int v : vec) {
    tmpAns->nxt = new VListNode<int>(v);
    tmpAns = tmpAns->nxt;
  }
  auto* to_delete = ans;
  ans = ans->nxt;
  delete to_delete;
  return ans;
}

VListNode<int>* NewOrderedIntVList(int l, int r) {
  std::vector<int> o;
  while (l <= r) {
    o.push_back(l++);
  }
  return CopyFromVectorInt(o);
}

}